<template>
  <basic-container>
    <h3>表格管理</h3>
    <avue-crud
      ref="crud"
      :option="option"
      :data="data"
      @row-save="rowSave"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @on-load="getList"
      @refresh-change="refreshChange"
      v-model:page="page"
      @search-change="searchChange"
      @search-reset="resetChange"
    >
    <template #menu="{ row, size }">
        <el-button :size="size" text type="primary" @click="handleAdd(row)"
          >生成控制器模型</el-button
        >
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import {  show,saveCrud } from "@/api/table.js";

export default {
  data() {
    return {
      page: {
        pagerCount: 6,
        pageSize: 10,
        total: 0,
        currentPage:1,
      },
 
      option: { 
        
        addBtn: false,
        delBtn: false,
        editBtn: false,
        columnBtn:false,
        rowKey: "TABLE_NAME",
        column: [
          {
            label: "表名",
            prop: "TABLE_NAME",  
          },
          {
            label: "备注",
            prop: "TABLE_COMMENT", 
          },
          {
            label: "记录数",
            prop: "TABLE_ROWS", 
          },
          {
            label: "引擎",
            prop: "ENGINE", 
          },
          {
            label: "字符集",
            prop: "TABLE_COLLATION", 
          },
          {
            label: "创建时间",
            prop: "CREATE_TIME", 
          },  
        ],
      },
      data: [],
    };
  },

  methods: {
    refreshChange() {
      this.getList();
    },

    getList(params) {
      this.loading = true;

      let par = { page: this.page.currentPage, limit: this.page.pageSize };
      if (params) {
        par = Object.assign(par, params);
      }
 
      show(par).then((res) => {
        this.loading = false;
        const data = res.data.data;
        this.data = data;
        this.page.total = res.data.count;
      });
    },
 
    //新增
    handleAdd(row) {
    
      saveCrud({table:row['TABLE_NAME']}).then((res) => {
          this.$message({
              type: "success",
              message: "添加成功!",
            });
        // this.getList();
      });
    
    }, 
  },
};
</script>
